package com.august.controller;

import com.august.service.CompareService;
import com.august.service.impl.CompanyVo;
import com.august.service.impl.HashVO;
import com.august.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/mysql")
@Slf4j
public class CompareController {

    @Autowired
    CompareService compareService;

    @RequestMapping("/1")
    public R list(@RequestParam Map<String, Object> params){
        List list = compareService.selectMySql1();
        return R.ok().put("data", list);
    }

    @RequestMapping("/2")
    public R list2(@RequestParam Map<String, Object> params){
        List list = compareService.selectMySql2();
        return R.ok().put("data", list);
    }

    @RequestMapping("/count")
    public R count(){
        return R.ok().put("data", compareService.selectCount());
    }

    @RequestMapping("/compare")
    public R compare(){

        //获取数据
//        List<CompanyVo> omsList = getOmsList();
//        //将要比对数据放入Map
//        Map<Long, CompanyVo> omsMap = new HashMap<Long, CompanyVo>();
//        for(CompanyVo vo:omsList){
//            omsMap.put(vo.getIdUuid(), vo);
//        }
//        //比较数据
//        compareCompany(omsMap);

        //Map<String, String> data1Map = new HashMap<String, String>();
        long begin = System.currentTimeMillis();
        List<HashVO> mySqyList = compareService.getMySqyList();

        log.info("size1: "+mySqyList.size());
        Map<String, String> hashMap = mySqyList.stream().collect(
                Collectors.toMap(HashVO::getReconKey, HashVO::getHashCode));

//        for(HashMap map:mySqyList){
//            data1Map.put(map., vo);
//        }

        log.info("size2: "+hashMap.size());

        compareService.compare((HashMap) hashMap,begin);

       //比较数据
        //compareCompany(omsMap);
//        long end = System.currentTimeMillis();
//
//        log.info("10万数据{}耗时:",end-begin);
        return R.ok().put("data", null);
    }

}
